#include <QString>
#include <QtTest>

#include "../MO_1-2/ConvolutionNet.h"

class Test_ConvolutionNetTest : public QObject
{
    Q_OBJECT
    
public:
    Test_ConvolutionNetTest();
    
private Q_SLOTS:
    void initTestCase();
    void testCase1_matrix_getSize();
    void testCase1_matrix_setGet();
    void testCase1_matrix_getFragment();
    void cleanupTestCase();
};

Test_ConvolutionNetTest::Test_ConvolutionNetTest()
{
}

void Test_ConvolutionNetTest::initTestCase()
{
}

void Test_ConvolutionNetTest::testCase1_matrix_getSize()
{ // тест для matrix::get_size()
    matrix m(4, 4, 1);
    QCOMPARE(16, m.get_size());
}

void Test_ConvolutionNetTest::testCase1_matrix_setGet()
{ // тест для matrix::set_matrix и matrix::get_matrix
    int width = 4, height = 4;
    matrix m(width, height, 1);
    double* pWeights = new double[width*height];
    for(int i =0; i < height* width; i++) pWeights[i] = (double)(rand()%10);
    m.set_matrix(pWeights);
    double* result = m.get_matrix();
    for(int i =0; i < height* width; i++) QCOMPARE(pWeights[i], result[i]);
}

void Test_ConvolutionNetTest::testCase1_matrix_getFragment()
{ // тест для matrix::get_fragment
    int width = 4, height = 4;
    matrix m(width, height, 1);
    double* pWeights = new double[width*height];
    for(int i =0; i < height* width; i++) pWeights[i] = (double)(rand()%10);
    m.set_matrix(pWeights);

    matrix fragment = m.get_fragment(2, 2, 0, 0);

    double* pResult1 = fragment.get_matrix();
    for(int i =0; i < 4; i++)
        QCOMPARE(pResult1[i], pWeights[(i/2)*width + i%2]);

    double* pResult2 = m.get_fragment(2, 2, 1, 1).get_matrix();
    for(int i =0; i < 4; i++)
        QCOMPARE(pResult2[i], pWeights[((i/2) + 1)*width + (i%2 + 1)]);
}

void Test_ConvolutionNetTest::cleanupTestCase(){}

QTEST_APPLESS_MAIN(Test_ConvolutionNetTest)

#include "Test_ConvolutionNetTest.moc"
